package com.weihoo.manager.controller;

import com.weihoo.manager.service.IHelloService;
import com.weihoo.manager.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author houyeping
 * @Date 2017/11/24 17:18
 * @Description
 * 方法一。使用ApplicationContext获取bean对象，然后在调用
 * 方法二。直接注入helloService，然后调用
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private ApplicationContext context;

    /**
     * 调用服务端方法
     * @return
     */
    @RequestMapping("/hello")
    public String hello(){
        IHelloService helloService = context.getBean(IHelloService.class);
        String result = helloService.hello("houyeping2222");
        return result;
    }

    @RequestMapping("/queryUser")
    public String queryUser(){
        IHelloService helloService = context.getBean(IHelloService.class);
        User user = helloService.queryUser();
        return user.toString();
    }


    @Autowired
    private IHelloService helloService;

    @RequestMapping("/hello2")
    public String hello2(){
        String result = helloService.hello("houyeping222233333");
        return result;
    }


}
